package com.hu.biz.util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Component;

/**
 * @ClassName SqlContext
 * @Description sql上下文
 * @author 355760
 **/
@Component
public class SqlContext {
    final private SqlSessionTemplate sqlSessionTemplate;

    public SqlContext(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    /**
     * 获取sql连接session
     * @return SqlSession
     */
    public SqlSession getSqlSession(){
        SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory();
        SqlSession sql =  sqlSessionFactory.openSession();
        return sqlSessionFactory.openSession();
    }
}
